//
//  LXTableViewCell.m
//  wdawdawdw
//
//  Created by 吕超 on 16/11/7.
//  Copyright © 2016年 lc. All rights reserved.
//

#import "LXTableViewCell.h"
#import "LXModel.h"
#define SuiJiYanSe [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1]

#define selfPingMuWidth [UIScreen mainScreen].bounds.size.width
#define selfPingMuHeight [UIScreen mainScreen].bounds.size.height


@interface LXTableViewCell ()

@end


@implementation LXTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self createSubView];
    }
    
    return self;
}



- (void)createSubView{
    
     //选择
    _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _selectBtn.frame = CGRectMake(10, 30, 20, 20);
   [_selectBtn setImage:[UIImage imageNamed:@"未选中"] forState:(UIControlStateNormal)];

    _selectBtn.selected = YES;
    [_selectBtn addTarget:self action:@selector(selectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.selectBtn];

    // 新闻内容
    _LXLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_selectBtn.frame) + 10, 10, selfPingMuWidth - 60, 60)];
    _LXLabel.font = [UIFont systemFontOfSize:15];
    
    _LXLabel.numberOfLines = 0;
    
    [self addSubview:self.LXLabel];
    
    
    // 减号
    _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.leftButton.backgroundColor = [UIColor grayColor];
    
    _leftButton.frame = CGRectMake(20, 80, 40, 30);
    
    [_leftButton setTitle:@"-" forState:UIControlStateNormal];
    
    [_leftButton addTarget:self action:@selector(jianButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.leftButton];

    
    //个数
    _numberTF = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_leftButton.frame) + 20, 80, selfPingMuWidth - 260, 30)];

    _numberTF.textColor = [UIColor whiteColor];
    
    _numberTF.backgroundColor = [UIColor grayColor];
    
    _numberTF.textAlignment = NSTextAlignmentCenter;
    
    _numberTF.keyboardType = UIKeyboardTypePhonePad;
    
    _numberTF.font = [UIFont systemFontOfSize:15];
    

    
    _numberTF.placeholder = @"0";
    
    [self addSubview:self.numberTF];
    
    
    //    加号
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    _rightButton.backgroundColor = [UIColor grayColor];
    
    _rightButton.frame = CGRectMake(CGRectGetMaxX(_numberTF.frame) + 20, 80, 40, 30);
    
    [_rightButton setTitle:@"+" forState:UIControlStateNormal];
    
    [_rightButton addTarget:self action:@selector(addButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.rightButton];
    
    
    //  价格
    _priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_rightButton.frame) + 20 , 80, 60, 30)];
    _priceLabel.font = [UIFont systemFontOfSize:15];
    _priceLabel.textColor = [UIColor blackColor];

    _priceLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.priceLabel];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    // 图片
    self.PictureImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.priceLabel.frame) + 10 , selfPingMuWidth  - 40, 100)];

    
    [self addSubview:self.PictureImage];
    
}




//增加 按钮  方法
- (void)addButtonAction:(UIButton *)btn{
    
    
    if ([self.delegate respondsToSelector:@selector(addButtonDelegate:)]) {
        
        [self.delegate addButtonDelegate:btn.tag];
    }
}



//减少 按钮 方法
- (void)jianButtonAction:(UIButton *)btn{
    
    if ([self.delegate respondsToSelector:@selector(jianButtonDelegate:)]){
        
        [self.delegate jianButtonDelegate:btn.tag];
       
    }
}




// 选择 图片  设置代理
- (void)selectButtonAction:(UIButton *)btn{
    
    if ([self.delegate respondsToSelector:@selector(selectAtIndex:)]) {
        self.selectBtn.selected = YES;
        [self.delegate selectAtIndex:btn.tag];
    }
}




- (void)setCellModel:(LXModel *)model{
    
    self.LXLabel.text = model.alias;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
